package com.salesforce.samples.templateapp;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;

public class InventoryActivity extends FragmentActivity implements InventoryListener{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_inventory);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.inventory, menu);
		return true;
	}

	@Override
	public void onWarehouseClicked(final int position) {
		// TODO Auto-generated method stub
		
		if(position >= 0){                
			WarehouseFragment newFragment = new WarehouseFragment();
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.inventoryviewer, newFragment);
			transaction.commit();
			
			 new Handler().postDelayed(new Runnable() {                      
		            @Override
		            public void run() {
		            
		            	WarehouseFragment warehouseFragment = (WarehouseFragment) getSupportFragmentManager().findFragmentById(R.id.inventoryviewer);
		            	warehouseFragment.getWarehouseDetails(position);
		            	
		            }
		        }, 2000);
		}
	}

}
